﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using DAL;
using Entities;

namespace SurveyGUI
{
    public partial class ListQuestionSurVeyForm : Form
    {
        IQuestionSurVeyRepository rep = new QuestionSurVeyRepository();

        string connectionString;
        DataSet ds;
        SqlDataAdapter da;
        DataTable dt;

        public ListQuestionSurVeyForm()
        {
            InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void LoadDefault()
        {
            connectionString = "Data Source=TRANNAMHAI-PC\\SQLEXPRESS;Initial Catalog=Nhom15;Integrated Security=True";
            SqlConnection con = new SqlConnection(connectionString);
            da = new SqlDataAdapter("Select * from CauHoiKhaoSat", con);
            dt = new DataTable();
            da.Fill(dt);


            dataGridViewListquestion.DataSource = dt;

        }

        private void ListQuestionSurVeyForm_Load(object sender, EventArgs e)
        {
            LoadDefault();
        }

        private void dataGridViewListquestion_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            lbGiaTri.Text = dataGridViewListquestion.CurrentRow.Cells[0].Value.ToString();
        }

        private void btndelete_Click(object sender, EventArgs e)
        {
           
            if (lbGiaTri.Text == "")
            {
                MessageBox.Show("Bạn chưa chọn câu hỏi để xóa...");
            }
            else
            {
                int id = int.Parse(lbGiaTri.Text);

                QuestionSurVey qv = rep.GetById(id);
                rep.DeleteQuestionSurVey(qv);
                LoadDefault();
            }
        }
    }
}
